# Maintainer: Martell Malone <martell malone at g mail dot com >

_realname=libwebsockets

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
_ver_base=1.23
pkgver=1.23.745.5b2d032
pkgrel=1
arch=('any')
pkgdesc="A lightweight pure C library for websockets (mingw-w64)"
url=('http://libwebsockets.org/')
license=('LGPL 2.1 - custom')
depends=("${MINGW_PACKAGE_PREFIX}-zlib" "${MINGW_PACKAGE_PREFIX}-openssl")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake" "${MINGW_PACKAGE_PREFIX}-gcc" 'unzip')
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
source=("${_realname}"::"git+http://github.com/martell/libwebsockets.git")
options=(!strip !buildflags staticlibs)
md5sums=('SKIP')

pkgver() {
  cd "$srcdir/$_realname"
  printf "%s.%s.%s" "$_ver_base" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

build() {
  mkdir -p ${pkgdir}${MINGW_PREFIX}
  pushd ${pkgdir}${MINGW_PREFIX} > /dev/null
  export PREFIX_WIN=`pwd -W`
  popd > /dev/null
  
  pushd ${MINGW_PREFIX} > /dev/null
  export PREFIX_DEPS=`pwd -W`
  popd > /dev/null

    cd "${srcdir}/${_realname}"
    ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DUSE_EXTERNAL_ZLIB=ON \
    -DCMAKE_C_COMPILER=${MINGW_PREFIX}/bin/gcc.exe \
    -DCMAKE_CXX_COMPILER=${MINGW_PREFIX}/bin/g++.exe \
    -DWITHOUT_DAEMONIZE=ON \
    -DWITHOUT_TESTAPPS=ON \
    -DCMAKE_INSTALL_PREFIX:PATH=${PREFIX_WIN} \
    -DCMAKE_BUILD_TYPE=RELEASE
    make
}

package() {
    cd "${srcdir}/${_realname}"
    make -j1 install
  mkdir -p ${pkgdir}${MINGW_PREFIX}/bin
  install -Dm644 "${srcdir}/${_realname}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
